/*
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.data;

import java.io.Serializable;

/**
 * A Cell's position (0..8) 
 * @author Emanuel Moecklin
 */
public class CellPosition implements Comparable<CellPosition>, Serializable {

	private static final long serialVersionUID = 1354331059233981362L;

	private int x;
	private int y;

	CellPosition(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	@Override
	public boolean equals(Object another) {
		CellPosition tmp = (CellPosition) ((another instanceof CellPosition) ? another : null);
		return (tmp==null) ? false : (tmp.x==x && tmp.y==y);
	}

	@Override
	public int compareTo(CellPosition another) {
		if (another==null) return -1;
		CellPosition tmp = (CellPosition) another;;
		int thisPos = y*9+x;
		int otherPos = tmp.y*9+tmp.x;
		return (thisPos<otherPos) ? -1 : (thisPos>otherPos) ? 1 : 0; 
	}
	
	@Override
	public int hashCode() {
		return (x<<16)+y;
	}

	@Override
	public String toString() {
		return "x=" + x + ", y=" + y; //$NON-NLS-1$ //$NON-NLS-2$
	}

}